#!/bin/bash
# Copyright (C) 2011-2020 Aratelia Limited - Juan A. Rubio and contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

#
# Simple tail wrapper that uses the grcat colorizer
#

TIZONIA_GRCAT_CONFIG="$TIZONIA_REPO_DIR"/tools/tizonia.grcat.conf
TIZONIA_LOG_FILE="$HOME"/temp/tizonia.log.0

declare -ar TIZONIA_TAIL_DEPS=( \
    'tail' \
    'cut' \
    'grcat' \
)

# Check dependencies
for cmd in "${TIZONIA_TAIL_DEPS[@]}"; do
    command -v "$cmd" >/dev/null 2>&1 \
        || { echo >&2 "This program requires $cmd. Aborting."; exit 1; }
done

tail -F "$TIZONIA_LOG_FILE" | awk '{for (i=5; i<NF; i++) printf $i " "; print $NF}' | grcat "$TIZONIA_GRCAT_CONFIG"

# tail -F "$TIZONIA_LOG_FILE" | cut -c 50- | sed 's/httpsrctrans.c//g' | sed 's/gmusicprc.c//g' | grcat "$TIZONIA_GRCAT_CONFIG"
# grep -E "debug_cback|socket_cback|write_cback|timer_cback" |
